<?php

namespace Modules\Car\Http\Controllers;

use App\Helpers\PayTrait;
use App\Helpers\ResponseData;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Car\Entities\RecognizeDrivingLicense;
use Modules\Car\Entities\Service;

//自己维修
class CustomServiceController extends Controller
{
    use ResponseData,PayTrait;
    public function list(Service $service,Request $request){
        $type = $request->input('type','');
        $car_id = $request->input('car_id','');
        $size = $request->input('size',10);
        if($type=='all'){
            $data = $service->query()
                ->with('car','sendPerson','series')
                ->when($car_id,function($query)use($car_id){
                    $query->where('car_id',$car_id);
                })
                ->orderBy('id','desc')
                ->get();
        }else{
            $data = $service->query()
                ->with('car','sendPerson','series')
                ->when($car_id,function($query)use($car_id){
                    $query->where('car_id',$car_id);
                })
                ->orderBy('id','desc')->paginate($size);
        }
        $arr['uncleared'] = Service::query()->where('is_custom',4)->where('status',4)->where('is_accident_sett',1)->count();
        $arr['repair_price'] = Service::query()->where('id','>',0)->count('repair_price');
        $arr['data']=$data;
        return $this->success($arr);
    }
    public function store(Service $service,Request $request){
        $data = $request->all();
        $service->fill($data);
        $service->save();
        return $this->success('保存成功');
    }
    public function edit(Service $service,Request $request){
        $data = $service->find($request->id);
        return $this->success($data);
    }
    public function update(Service $service,Request $request){
        $data = $service->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(Service $service,Request $request){
        $data = $service->find($request->id);
        $data->delete();
    }
}
